package com.atguigu.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@EnableConfigurationProperties(RedisProperties.class)
//@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedissonConfig {

    /**
     * 方式一
     * 采用@Value("${spring.redis.host}")
     * 方式二
     * @Autowired private RedisProperties redisProperties;
     * a.RedisAutoConfiguration里面参看 @EnableConfigurationProperties(RedisProperties.class)
     * b.WebMvcAutoConfiguration里面参看 WebMvcAutoConfiguration
     */

    @Bean
    public RedissonClient redissonClient(RedisProperties redisProperties) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

//    @Bean
//    public RedissonClient redissonClient(RedisProperties redisProperties) {
//        Config config = new Config();
//        config.useSingleServer().setAddress("redis://192.168.36.128:6389");
//        RedissonClient redisson = Redisson.create(config);
//        return redisson;
//    }

}
